package org.tigris.subversion.svnant.commands;

import java.io.File;
import java.net.MalformedURLException;
import java.util.Date;
import org.apache.tools.ant.Project;
import org.tigris.subversion.svnant.SvnAntUtilities;
import org.tigris.subversion.svnclientadapter.ISVNClientAdapter;
import org.tigris.subversion.svnclientadapter.ISVNInfo;
import org.tigris.subversion.svnclientadapter.SVNClientException;
import org.tigris.subversion.svnclientadapter.SVNNodeKind;
import org.tigris.subversion.svnclientadapter.SVNRevision;
import org.tigris.subversion.svnclientadapter.SVNRevision.Number;
import org.tigris.subversion.svnclientadapter.SVNUrl;

public class Info extends SvnCommand
{
  private static final String MSG_FAILED_TO_SET_INFO_PROPS = "Failed to set 'info' properties";
  private static final String MSG_UNSUPPORTED_OPTION = "The attribute 'verbose' is no longer supported for the command 'info' as it's generally enabled using the Ant option -v !";
  private String target = null;
  private String propPrefix = "svn.info.";
  private ISVNInfo info = null;
  private static final String[] DIR_PROP_NAMES = { "path", "url", "repourl", "repouuid", "rev", "nodekind", "schedule", "author", "lastRev", "lastDate" };
  private static final String[] FILE_PROP_NAMES = { "path", "name", "url", "repourl", "repouuid", "rev", "nodekind", "schedule", "author", "lastRev", "lastDate", "lastTextUpdate", "lastPropUpdate", "checksum" };

  public void execute()
  {
    Project localProject = getProject();
    try
    {
      this.info = acquireInfo();
      if ((this.info.getRevision() == null) || (SVNRevision.INVALID_REVISION.equals(this.info.getRevision())))
        throw ex("%s - Not a versioned resource", new Object[] { this.target });
      String[] arrayOfString = SVNNodeKind.DIR == this.info.getNodeKind() ? DIR_PROP_NAMES : FILE_PROP_NAMES;
      for (int i = 0; i < arrayOfString.length; i++)
      {
        String str = getValue(arrayOfString[i]);
        localProject.setProperty(this.propPrefix + arrayOfString[i], str);
        verbose("%s%s: %s", new Object[] { this.propPrefix, arrayOfString[i], str });
      }
    }
    catch (SVNClientException localSVNClientException)
    {
      throw ex(localSVNClientException, "Failed to set 'info' properties", new Object[0]);
    }
  }

  private ISVNInfo acquireInfo()
    throws SVNClientException
  {
    File localFile = new File(Project.translatePath(this.target));
    if (localFile.exists())
      return getClient().getInfo(localFile);
    try
    {
      SVNUrl localSVNUrl = new SVNUrl(this.target);
      return getClient().getInfo(localSVNUrl);
    }
    catch (MalformedURLException localMalformedURLException)
    {
    }
    return getClient().getInfo(localFile);
  }

  public String getValue(String paramString)
  {
    Object localObject = null;
    if (FILE_PROP_NAMES[0].equals(paramString))
    {
      localObject = this.info.getFile();
      if (localObject != null)
        localObject = ((File)localObject).getAbsolutePath();
      else
        localObject = this.info.getUrl().getLastPathSegment();
    }
    else if (FILE_PROP_NAMES[1].equals(paramString))
    {
      localObject = this.info.getFile();
      if (localObject != null)
        localObject = ((File)localObject).getName();
      else
        localObject = this.info.getUrl().getLastPathSegment();
    }
    else if (FILE_PROP_NAMES[2].equals(paramString))
    {
      localObject = this.info.getUrl();
    }
    else if (FILE_PROP_NAMES[3].equals(paramString))
    {
      localObject = this.info.getRepository();
    }
    else if (FILE_PROP_NAMES[4].equals(paramString))
    {
      localObject = this.info.getUuid();
    }
    else if (FILE_PROP_NAMES[5].equals(paramString))
    {
      localObject = this.info.getRevision();
    }
    else if (FILE_PROP_NAMES[6].equals(paramString))
    {
      localObject = this.info.getNodeKind();
    }
    else if (FILE_PROP_NAMES[7].equals(paramString))
    {
      localObject = this.info.getSchedule();
    }
    else if (FILE_PROP_NAMES[8].equals(paramString))
    {
      localObject = this.info.getLastCommitAuthor();
    }
    else if (FILE_PROP_NAMES[9].equals(paramString))
    {
      localObject = this.info.getLastChangedRevision();
    }
    else
    {
      Date localDate;
      if (FILE_PROP_NAMES[10].equals(paramString))
      {
        localDate = this.info.getLastChangedDate();
        if (localDate != null)
          localObject = getDateStringFor(localDate);
      }
      else if (FILE_PROP_NAMES[11].equals(paramString))
      {
        localDate = this.info.getLastDateTextUpdate();
        if (localDate != null)
          localObject = getDateStringFor(localDate);
      }
      else if (FILE_PROP_NAMES[12].equals(paramString))
      {
        localDate = this.info.getLastDatePropsUpdate();
        if (localDate != null)
          localObject = getDateStringFor(localDate);
      }
      else if (FILE_PROP_NAMES[13].equals(paramString))
      {
        warning("    Property '%s' not implemented", new Object[] { paramString });
      }
      else
      {
        warning("    Property '%s' not recognized", new Object[] { paramString });
      }
    }
    return localObject == null ? "" : (String)localObject.toString();
  }

  protected void validateAttributes()
  {
    SvnAntUtilities.attrNotNull("target", this.target);
  }

  public void setTarget(String paramString)
  {
    this.target = paramString;
  }

  public void setVerbose(boolean paramBoolean)
  {
    warning("The attribute 'verbose' is no longer supported for the command 'info' as it's generally enabled using the Ant option -v !", new Object[0]);
  }

  public void setPropPrefix(String paramString)
  {
    if (paramString.endsWith("."))
      this.propPrefix = paramString;
    else
      this.propPrefix = (paramString + '.');
  }
}

/* Location:           C:\Users\Administrator\Desktop\svnant.jar
 * Qualified Name:     org.tigris.subversion.svnant.commands.Info
 * JD-Core Version:    0.6.0
 */